<?php
namespace app\user\controller\admin;

use app\common\controller\Back;

class Score extends Back
{
    protected function initialize()
    {
        parent::initialize();
    }
    
    public function index()
    {
        $form = dcFormCreate([
            'name'         => 'adminScoreIndex',
            'action'       => dcUrl('user/admin.score/update'),
            'items'        => $this->formItems(config('score.')),
            'reset'        => '重置',
            'class_button' => 'text-left',
        ]);

        $this->assign('form',$form);

        $this->assign($this->site);

        return $this->fetch('admin.score/index');
    }

    public function update()
    {
        $post = dcArrayFilter(input('post.'), array_keys($this->formItems()));
        if(!$post){
            $this->error('参数错误');
        }

        $this->configSave('./config/score.php', $post, 'user/admin.score/index');
    }
    
    private function formItems($data=[])
    {
        return [
            'recharge' => [
                'type'        => 'text',
                'value'       => $data['recharge'],
                'title'       => '积分充值比例',
                'required'    => false,
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'register' => [
                'type'        => 'text',
                'value'       => $data['register'],
                'title'       => '注册赠送积分',
                'required'    => false,
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'reward' => [
                'type'        => 'text',
                'value'       => $data['reward'],
                'title'       => '推广奖励积分',
                'required'    => false,
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
        ];
    }
}